package com.vincent.gdb.test.http;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nonnull;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.common.collect.Lists;
import com.vincent.gdb.test.types.HelloBean;

//The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {

	// The Java method will process HTTP GET requests
	@GET
	// The Java method will produce content identified by the MIME Media
	// type "text/plain"
	@Produces(MediaType.TEXT_PLAIN)
	public String getClichedMessage() {
		// Return some cliched textual content
		return "Hello World";
	}

	@GET
	@Path("/json/get")
	@Produces(MediaType.APPLICATION_JSON)
	public HelloBean getJsonForm() {
		HelloBean bean = new HelloBean();
		bean.setTopic("test");
		List<String> people = Lists.newArrayList();
		people.add("johnson");
		bean.setPeople(people);
		String[] address = { "HongKong" };
		bean.setAddress(address);

		return bean;

	}

	@POST
	@Path("/json/post")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String postJsonForm(@Nonnull HelloBean bean) {
		
		String result = "the topic is:" + bean.getTopic()
				+ " and num of people is: " + bean.getPeople().size()
				+ " and the addresses are:" + Arrays.toString(bean.getAddress());
		
		
		return result;
	}
}